<html>
<head>
<title>The Life Cycle of an Applet</title>
</head>
<body>
<table width=100%>
<tr>
<td align=left>
<a href="index.html"><img src=../../images/PreviousArrow.gif width=26 height=26 align=bottom border=0 alt="Previous | "></a><a
href="appletMethods.html"><img src=../../images/NextArrow.gif width=26 height=26 align=bottom border=0 alt="Next | "></a><a
href="../../index.html"><img src=../../images/WayUpArrow.gif width=26 height=26 align=bottom border=0 alt="Trail Map | "></a><a
href="../index.html"><img src=../../images/appletHeader.gif width=26 height=26 align=bottom border=0 alt="Writing Applets | "></a>
<td>
<td align=right>
<a href="index.html"><strong><em>The Anatomy of an Applet</em></strong></a>
</td>
</tr>
</table>
<p>
<hr size=4>

<h2>
    The Life Cycle of an Applet
</h2>
<p>
<blockquote>



<a name="output">
<!--FILE BUG; THIS DOESN'T WORK when put around the APP tag; SHOULDN'T IT?-->
Below (if you're running a Java-compatible browser)
is the Simple applet.
</a>
<p>

<applet code="Simple.class" codebase=betaclasses width=500 height=20>
<APP class=Simple width=500 height=20>
</applet>
<p>

<a name="loading"><h4>Loading the Applet</h4></a>
<blockquote>
You should see "initializing... starting..." above,
as the result of the applet being loaded.
When an applet is loaded,
here's what happens:
<ul>
<li> An instance of the applet's controlling class is created.
<li> The applet <b>initializes</b> itself.
<li> The applet <b>starts</b> running.
</ul>

</blockquote>

<a name="leaving"><h4>Leaving and Returning to the Applet's Page</h4></a>
<blockquote>
When the user leaves the page
-- for example, to go to another page --
the applet has the option of <b>stopping</b> itself.
When the user returns to the page,
the applet can <b>start</b> itself again.


<p>

<strong>Try this:</strong>
Leave and then return to this page.
You'll see "stopping..." added to the
<a href="#output">applet output above</a>,
as the applet is given the chance to stop itself.
You'll also see "starting...",
when the applet is told to start itself again.
</blockquote>

<a name="reloading"><h4>Reloading the Applet's Page</h4></a>
<blockquote>
When the user reloads the page,
the applet is unloaded and reloaded.
So that the applet can release any resources it holds,
it's given the chance to <b>stop</b> itself
and then to perform a <b>final cleanup</b>.
After that, the applet is unloaded
and then loaded as described in
<a href="#loading"><b>Loading the Applet</b></a>,
above.
<p>

<strong>Try this:</strong>
Look at the 
<a href="_stdout.html">standard output</a>
to see what happens when you reload this page.
You should see "stopping..." and "preparing for unloading..."
when the applet is unloaded.
(You can't see this in the applet above
because the applet is unloaded before the text can be displayed.)
When the applet is reloaded,
you should see "initializing..." and "starting...",
just like when you loaded the applet for the first time.
</blockquote>

<a name="quitting"><h4>Quitting the Browser</h4></a>
<blockquote>
When the user quits the browser 
(or whatever application is displaying the applet),
the applet has the chance to <b>stop</b> itself and do <b>final cleanup</b>
before the browser exits.
</blockquote>

</blockquote>
<p>
<hr size=4>
<p>
<table width=100%>
<tr>
<td align=left>
<a href="index.html"><img src=../../images/PreviousArrow.gif width=26 height=26 align=top border=0 alt="Previous | "></a><a
href="appletMethods.html"><img src=../../images/NextArrow.gif width=26 height=26 align=top border=0 alt="Next | "></a><a
href="../../index.html"><img src=../../images/WayUpArrow.gif width=26 height=26 align=top border=0 alt="Trail Map | "></a><a
href="../index.html"><img src=../../images/appletHeader.gif width=26 height=26 align=top border=0 alt="Writing Applets | "></a>
<td>
<td align=right>
<a href="index.html"><strong><em>The Anatomy of an Applet</em></strong></a>
</td>
</tr>
</table>
</body>
</html>
